Page({
  data: {
    account: '',
    userInfo: {} // 用于存储用户输入的信息
  },

  onConfirm: function() {
    wx.cloud.callFunction({
      name: "Health_insurance",
      config: {
        env: this.data.envId
      },
      data: {
        type: "check_yes",
        data: {
          account: this.data.account,
        }
      },
      success: res => {
        wx.showToast({
          title: '购买确认',
          icon: 'success',
          duration: 1000,
          success: () => {
            // 在延迟后跳转到指定页面
            setTimeout(() => {
              wx.navigateTo({
                url: '/pages/navigation/navigation' // 跳转到目标页面
              });
            }, 1000); // 与toast持续时间一致
          }
        });
        getApp().globalData.purchaseStatus = 'Confirmed'; // 更新购买状态为已确认
      },
      fail: res => {
        console.log(res);
        wx.showToast({
          title: '失败',
          icon: "none"
        });
      }
    });
  },

  onCancel: function() {
    getApp().globalData.purchaseStatus = 'notConfirmed'; // 更新购买状态为未确认
    wx.navigateTo({
      url: '/pages/reason/reason?account=' + this.data.account,
    });
  },

  onLoad(options) {
    if (options.account) {
      this.setData({
        account: options.account
      });
    }
    getApp().globalData.purchaseStatus = 'notSelected'; // 初始化购买状态为未选择
  },
});
